package teaMainFrame;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.rORM.core.MysqlQuery;
import com.rORM.core.Query;
import com.rORM.core.QueryFactory;

import database.TeacherTable;

import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class CreateTeacherTable extends JFrame {
	TeacherTable t = new TeacherTable();
	
	private JPanel contentPane;
	private JTextField textField;
	private int userid;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					CreateTeacherTable frame = new CreateTeacherTable(123);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public CreateTeacherTable(int userid) {
		setVisible(true);
		this.userid = userid;
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setLocationRelativeTo(getOwner());
		setResizable(false);
		setSize(450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("创建课表");
		lblNewLabel.setFont(new Font("Dialog", Font.PLAIN, 19));
		lblNewLabel.setBounds(173, 17, 77, 30);
		contentPane.add(lblNewLabel);
		
		JLabel label = new JLabel("请输入课程号");
		label.setFont(new Font("Dialog", Font.PLAIN, 19));
		label.setBounds(54, 82, 114, 30);
		contentPane.add(label);
		
		textField = new JTextField();
		textField.setBounds(229, 87, 130, 26);
		contentPane.add(textField);
		textField.setColumns(10);
		
		JButton button = new JButton("提交");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				t.setLessonID(Integer.parseInt(textField.getText()));
				t.setTeacherID(userid);
				InputTeacherTable(t);
				JOptionPane.showMessageDialog(null,"输入成功","信息提示框",JOptionPane.INFORMATION_MESSAGE);
			}
		});
		button.setBounds(279, 205, 117, 29);
		contentPane.add(button);
		
		JButton button_1 = new JButton("返回");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				setVisible(false);
			}
		});
		button_1.setBounds(109, 205, 107, 29);
		contentPane.add(button_1);
	}
	public void InputTeacherTable(TeacherTable t){
		new MysqlQuery().insert(t);
	}
}
